exports.MallMainView = UI.View.subclass(
{
    className: "MallMainView",
    initialize: function($super) 
    {
    	$super();
        this.setFrame([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(320),TCUtil.getAdjustedY(480)]);
        
        this._backgroundImage = null;
        this._closeBtn = null;
        this._topLabel = null;
        this._tableView = null;
        this._newMallBtn = null;
        this._tutorialPopup = null;
    },
    
    createView: function()
    {
    	this.addBackground();
        this.addCloseBtn();
        this.addTopLabel();
        this.addNewMallBth();
        this._tableView = new MallGenericTableView(this);
        this.addChild(this._tableView);
        this.checkAndAddTutorialPopup();
    },
 	
 	checkAndAddTutorialPopup: function()
 	{
 		if(!TutorialManager.getHasCompletedTutorial() && !DatabaseInterface._isVisitingNeighbor)
 		{
	 		this._tutorialPopup = new UITextAlert(Core.Localization.getString("TUTORIAL_TEXT_0"));
	 		this._tutorialPopup.createView();
	 		this._tutorialPopup.setCurrentPosition([TCUtil.getAdjustedX(55),TCUtil.getAdjustedY(220)]);
	 		this.addChild(this._tutorialPopup);
 		}
 		else if(!TutorialManager.getHasCompletedTutorial() && DatabaseInterface._isVisitingNeighbor)
 		{
	 		this._tutorialPopup = new UITextAlert(Core.Localization.getString("TUTORIAL_TEXT_12_C"));
	 		this._tutorialPopup.createView();
	 		this._tutorialPopup.setCurrentPosition([TCUtil.getAdjustedX(55),TCUtil.getAdjustedY(220)]);
	 		this.addChild(this._tutorialPopup);
// 			TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(150)]);
// 			TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_12_C"));
 		}
 	},
 	
 	removeTutorialPopup: function()
 	{
		if(!TutorialManager.getHasCompletedTutorial())
 		{
 			if(this._tutorialPopup)
 			{
	 			this._tutorialPopup.destroy();
	 			this._tutorialPopup = null;
 			}
 		} 	
	 },
 	
    addBackground: function()
    {
    	var backgroundImagePath = this.getBaseResourcePath() + "main-menu-background.png";
		this._backgroundImage = UIFactory.getImage([TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(10),TCUtil.getAdjustedX(300),TCUtil.getAdjustedY(460)], backgroundImagePath); 
        this.addChild(this._backgroundImage);
    },
    
    addCloseBtn: function()
    {
    	return;
    	var closeButtonNormalImagePath = this.getBaseResourcePath() + "close-button-normal.png";
    	var closeButtonSelectedImagePath = this.getBaseResourcePath() + "close-button-pressed.png";
    	
    	this._closeBtn = UIFactory.getGenericButton([TCUtil.getAdjustedX(275), TCUtil.getAdjustedY(40), TCUtil.getAdjustedY(40), TCUtil.getAdjustedX(40)], closeButtonNormalImagePath,closeButtonSelectedImagePath,null,null,null, this);	
		this.addChild(this._closeBtn);
		
		this._closeBtn.onclick = function()
    	{
			this.removeFromParent();
			this.destroy();
   		}.bind(this); 
    },
    
    addTopLabel: function()
    {
    	this._topLabel = UIFactory.getTextArea([TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(30), TCUtil.getAdjustedX(120), TCUtil.getAdjustedY(45)], Core.Localization.getString("mallSelectionTopLabel"), TCUtil.getAdjustedFontSize(100), UI.ViewGeometry.Gravity.Center);
	   	this.addChild(this._topLabel);
    },
    
    addNewMallBth: function()
    {
    	//console.log("zaki::::: DatabaseInterface._isVisitingNeighbor"+DatabaseInterface._isVisitingNeighbor);
    	if(!DatabaseInterface._isVisitingNeighbor)
    	{
	    	if(MMGameState.getCurrentUser().getHasCompletedTutorial())
	    	{
		    	var newMallButtonNormalImagePath = this.getBaseResourcePath() + "generic-button-normal.png";
		    	var newMallButtonSelectedImagePath = this.getBaseResourcePath() + "generic-button-pressed.png";
		    	
		    	this._newMallBtn = UIFactory.getGenericButton([TCUtil.getAdjustedX(110), TCUtil.getAdjustedY(395), TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], newMallButtonNormalImagePath, newMallButtonSelectedImagePath, Core.Localization.getString("NEW"), "000000", TCUtil.getAdjustedFontSize(120), this);	
				this.addChild(this._newMallBtn);
				
				this._newMallBtn.onclick = function()
		    	{
					this.editTextArea = new MMEditTextAlert(Core.Localization.getString('enterMallName'), this , 15);
					this.editTextArea.setTagValue(3333);
					this.editTextArea.show();
		    		
					//this.removeFromParent();
					//this.destroy();
		   		}.bind(this); 
	    	}
    	}
    },
    
    getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/mallselectionscreen/";
	},
	
	clickedButtonAtIndex: function(buttonIndex,alerWindow)
	{
		
		if (buttonIndex == 0) 
		{
			if(alerWindow.getTagValue() == 3333)
			{
				var mallName = alerWindow.getText();				
				if(mallName.length > 0 && mallName[0] != '\n' && mallName[0] != " " && isValidString(mallName))
				{
					MMGameState.getCurrentUser().addMall(mallName);
		    		if(this._tableView)
		    		{
		    			this._tableView.reloadTableView();
		    		}
					alerWindow.destroy();
					this.editTextArea = null;
				}
				else
				{
					var alertBox = UIFactory.getAlertBox(Core.Localization.getString("ERROR"), Core.Localization.getString("INVALID_NAME_RETRY"), ["Ok"], this);
					//show alert for invalid text and dont destroy edittext
				}
			}
		} 
		else if (buttonIndex == 1)
		{
			if(alerWindow.getTagValue() == 3333)
			{
				alerWindow.destroy();
			}			
		}
	},

    destroy: function()
    {
    	if(this._backgroundImage)
    	{
    		this._backgroundImage.destroy();
    		this._backgroundImage = null;
    	}
    	if(this._newMallBtn)
    	{
    		this._newMallBtn.destroy();
    		this._newMallBtn = null;
    	}
    	if(this._closeBtn)
    	{
    		this._closeBtn.destroy();
    		this._closeBtn = null;
    	}
    	if(this._topLabel)
    	{
    		this._topLabel.destroy();
    		this._topLabel = null;
    	}
    	if(this._tableView)
    	{
    		this._tableView.destroy();
    		this._tableView = null;
    	}
    	if(this._tutorialPopup)
    	{
    		this._tutorialPopup.destroy();
    		this._tutorialPopup = null;
    		
    	}
    },
});
